﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Kiosk.Utilities
{
    /// <summary>
    /// The Class that will have the XML config file data loaded into it via the configuration Manager.
    /// </summary>
    public class RssConfigSection : ConfigurationSection
    {
        /// <summary>
        /// The value of the property here "Folders" needs to match that of the config file section
        /// </summary>
        [ConfigurationProperty("feeds")]
        public FeedCollection FeedItems
        {

            get { return ((FeedCollection)(base["feeds"])); }

        }

    }

    /// <summary>
    /// The collection class that will store the list of each element/item that
    ///        is returned back from the configuration manager.
    /// </summary>
    [ConfigurationCollection(typeof(FeedElement))]
    public class FeedCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new FeedElement();
        }
        protected override object GetElementKey(ConfigurationElement element)
        {

            return ((FeedElement)(element)).Title;

        }
        public FeedElement this[int idx]
        {
            get
            {
                return (FeedElement)BaseGet(idx);
            }
        }

    }

    /// <summary>
    /// The class that holds onto each element returned by the configuration manager.
    /// </summary>
    public class FeedElement : ConfigurationElement
    {
        [ConfigurationProperty("title", DefaultValue = "", IsKey = true, IsRequired = true)]
        public string Title
        {
            get
            {
                return ((string)(base["title"]));
            }
            set
            {
                base["title"] = value;
            }

        }

        [ConfigurationProperty("url", DefaultValue = "", IsKey = false, IsRequired = true)]
        public string Url
        {
            get
            {
                return ((string)(base["url"]));
            }
            set
            {
                base["url"] = value;
            }
        }
    }
}
